package Ep06_BinaryTree.BT16_0513;

import Ep06_BinaryTree.TreeNode;

/**
 * DepthOrder
 *
 * @author Jimmy
 * @date 2023/5/10 15:42
 * @description:
 */
public class DepthOrder {
    private int RES = 0;
    private int MAX_DEPTH = -1;

    public int findBottomLeftValue(TreeNode root) {
        RES = root.val;
        traversal(root, 0);
        return RES;
    }

    private void traversal(TreeNode root, int depth){
        if (root == null) return;

        if (root.left == null && root.right == null){   // 判断是否是叶子结点
            if (depth > MAX_DEPTH){
                MAX_DEPTH = depth;
                RES = root.val;
            }
            return;
        }
        if (root.left != null) traversal(root.left, depth+1);
        if (root.right != null) traversal(root.right, depth+1);
    }
}
